﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SDSTextBox
{


    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:SDSTextBox runat=server></{0}:SDSTextBox>")]
    public class SDSTextBox : TextBox
    {
        //bool indexchg = false;
        //public delegate void FirstFocusEventHandler(Object sender, EventArgs e);
        //public event FirstFocusEventHandler FirstFocus;
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        protected override void Render(HtmlTextWriter writer)
        {
            if (!base.ReadOnly)
            {
                base.Render(writer);
            }
            else
            {
                base.AddAttributesToRender(writer);

                if (!this.DesignMode)
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Style, this.Style.Value + "float:left;text-align:left;");
                    if (!string.IsNullOrEmpty(this.CssClass))
                    {
                        writer.AddAttribute(HtmlTextWriterAttribute.Class, this.CssClass);
                    }

                    //writer.AddStyleAttribute(HtmlTextWriterStyle.FontFamily, this.Font.Name);
                    //writer.AddAttribute(HtmlTextWriterAttribute.Size, Font.Size.ToString());
                    //writer.AddAttribute(HtmlTextWriterAttribute.Background, this.BackColor.ToArgb().ToString());
                    writer.AddStyleAttribute(HtmlTextWriterStyle.Color, "#333333");
                    writer.AddAttribute(HtmlTextWriterAttribute.Id, this.ID);
                    writer.RenderBeginTag(HtmlTextWriterTag.Label);
                    writer.Write(base.Text);
                    writer.RenderEndTag();
                }

                //Else in design mode, then render specific texts
                else
                {
                    writer.Write("[" + this.ID + "]");
                }
            }
        }
        
    }

}
